/**
* @class
* Displays a jQuery UI dialog when notified by ksg.ui.messenger that there is a message to display
* if the level provided is one of the levels listed in options.displayLevels.
* @meta-type jQuery widget
* @Depends ksg.baseWidget.js
*/
ksg.ui.widgets.PopupDialogMessenger = {
	options: {
		displayLevels: [ksg.ui.messenger.levels.warning, ksg.ui.messenger.levels.error]
	},
	
	_create: function() { var self = this; var $this = this.element;
		$this.dialog({
			autoOpen: false,
			modal: true,
			buttons: {
				"Close": function () {
					$(this).dialog("close");
				}
			}
		});
		
		ksg.ui.messenger.addObserver(function(msg) {
			if(self.options.displayLevels.indexOf(msg.level) != -1) {
				var title = "Notice";
				if(msg.level == ksg.ui.messenger.levels.warning)
					title = "Warning";
				else if(msg.level == ksg.ui.messenger.levels.error)
					title = "Error";
				$this.dialog("option", "title", title);
				$this.html(msg.text);
				$this.dialog("open");
			}
		});
	}
};
$.widget("ksg.popupDialogMessenger", ksg.ui.widgets.PopupDialogMessenger);

ksg.ui.widgetMap["ksg-popupDialogMessenger"] = function ($el, options) {
	$el.popupDialogMessenger(options); 
};

